package org.example.boot.usercenter.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${image.upload-dir}")
    private String uploadDir;
    @Value("${image.upload-saveTime}")
    private int uploadSaveTime;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/getImages/**")   // 映射的URL路径
                .addResourceLocations("file:" + uploadDir + "/") // 本地存储路径
                .setCachePeriod(uploadSaveTime);  // 缓存时间（秒）
    }
}